<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>通知-新增</title>
        <meta name="renderer" content="webkit">
        <link rel="stylesheet" href="../../css/font.css"/>
        <link rel="stylesheet" href="../../css/xadmin.css"/>
        <script src="../../lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../js/xadmin.js"></script>
        <script src="../../js/vue2.7min.js"></script>
        <script src="../../js/axios.min.js"></script>
    </head>
    <body>
        <div class="layui-fluid" id="app">
            <div class="layui-row">


                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>通知标题</label>
                    <div class="layui-input-inline">
                        <input type="text" required="" lay-verify="name" autocomplete="off"
                               class="layui-input"
                               v-model="noticeTitle"></div>
                    <div class="layui-form-mid layui-word-aux">2到20个字符</div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>通知内容</label>
                    <div class="layui-input-inline">
                        <textarea  rows="10" cols="20" required="" lay-verify="name" autocomplete="off"
                               class="layui-input"
                                   v-model="noticeMessage">

                        </textarea>
                    </div>
                    <div class="layui-form-mid layui-word-aux">2到255个字符</div>
                </div>



            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-submit="" @click="add">增加</button>
            </div>
        </div>
        <script type="text/javascript">
            var vm = new Vue({
                el: "#app",
                data: {
                    noticeTitle: null,
                    noticeMessage: null
                },
                methods: {
                    add() {
                        //首先校验数据合法性
                        if (vm.noticeTitle === null || vm.noticeTitle === "" || vm.noticeTitle.length < 2 || vm.noticeTitle.length > 255) {
                            layer.alert("标题不可为空且长度在[2-200]哦", {
                                icon: 6
                            })
                        } else if (vm.noticeMessage === null || vm.noticeMessage === "" || vm.noticeMessage.length < 2 || vm.noticeMessage.length > 255) {
                            layer.alert("内容不可为空且长度在[2-200]哦", {
                                icon: 6
                            })
                        } else {
                            console.log("开始上传数据");
                            //开始axios通信
                            var jsonData = {
                                noticeTitle: vm.noticeTitle,
                                noticeMessage: vm.noticeMessage
                            }
                            axios.post("../../../notice/add", jsonData)
                                .then(function (response) {
                                    //数据保存到vue全局
                                    console.log(response)
                                    if (response.data.code === 1) {
                                        layer.alert("数据新增成功", {
                                            icon: 6
                                        })
                                    }
                                }, function (err) {
                                    console.log(err);

                                })
                        }


                    }
                }
            });
        </script>
    </body>

</html>